<?php 
namespace app\api\controller\v1;

use think\Controller;

class Ad extends Controller
{
    public function reader()
    { 
        $requests  = input('post.');
		$id  = input('post.id');
		$tname  = input('post.tname');
		$type  = input('post.type');
        $size = input('size') ? input('size') : 20;
        $model = model('Ad');
        $data = $model->reader($size,$tname,$type);// 查询数据
        if ($data) {
            $code = 200;
        } else {
            $code = 404;
        }
        $data = [
            'code' => $code,
            'data' => $data
        ];
        return json($data);
    }
	public function getad()
	{
	    $id = input('post.id');
	    $model = model('Ad');
	    $data = $model->getad($id);// 查询数据
	    if ($data) {
	        $code = 200;
	    } else {
	        $code = 404;
	    }
	    $data = [
	        'code' => $code,
	        'data' => $data
	    ];
	    return json($data);
	}
	public function zt()
	{
		header('Access-Control-Allow-Origin: *');
		header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
		header('Access-Control-Allow-Methods: GET, POST, PUT');
		$shuju = input('post.');
	    $id = input('id');
		$zt = input('zt');
	    $model = model('Ad');
	    $data = $model->zt($id,$zt);// 添加数据
	    if ($data) {
	        $code = 200;
	    } else {
	        $code = 404;
	    }
	    $data = [
	        'code' => $code,
	        'data' => $data
	    ];
	    return json($data);
	}
	public function add()
	{
	    header('Access-Control-Allow-Origin: *');
	    header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
	    header('Access-Control-Allow-Methods: GET, POST, PUT');
	    $shuju = input('post.');
	    // $shuju =['name' => 'thinkphp', 'content' => 'thinkphp'];
	    $model = model('Ad');
	    $data = $model->add($shuju);// 添加数据
	    if ($data) {
	        $code = 200;
	    } else {
	        $code = 404;
	    }
	    $data = [
	        'code' => $code,
	        'data' => $data
	    ];
	    return json($data);
	}
	public function del()
	{   
	    $id = input('post.id');
	    $model = model('Ad');
	    $data = $model->del($id);//删除数据
	    if ($data) {
	        $code = 200;
	    } else {
	        $code = 404;
	    }
	    $data = [
	        'code' => $code,
	        'data' => $data
	    ];
	    return json($data);
	}
	public function delArr()
	{   
	    $id =  input('post.id/a',array());
	    $model = model('Ad');
	    $data = $model->del($id);//删除数据
	    if ($data) {
	        $code = 200;
	    } else {
	        $code = 404;
	    }
	    $data = [
	        'code' => $code,
	        'data' => $data
	    ];
	    return json($data);
	}
	public function getaded()
	{
	    header('Access-Control-Allow-Origin: *');
	    header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
	    header('Access-Control-Allow-Methods: GET, POST, PUT');
	    $shuju = input('post.');
	    $id = input('id');
	    $model = model('Ad');
	    $data = $model->edit($id,$shuju);// 添加数据
	    if ($data) {
	        $code = 200;
	    } else {
	        $code = 404;
	    }
	    $data = [
	        'code' => $code,
	        'data' => $data
	    ];
	    return json($data);
	}
	
}